export default function _confirm(content) {
    return new Promise((resolve, reject) => {
        const html = String.raw;
        const str = html`
        <div class="modal" style="display: block;">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                      提示
                    </div>
                    <div class="modal-body">
                        ${content}
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-modal-close>取消</button>
                        <button type="button" class="btn btn-primary" data-modal-confirm>确定</button>
                    </div>
                </div>
            </div>
        </div>
    `;
        // 将html插入到body中
        const div = document.createElement('div');
        div.innerHTML = str;
        div.onclick = function (e) {
            const target = e.target;
            // 用户点击了取消
            if (target.dataset.modalClose !== undefined) {
                div.remove();
                reject(new Error(false));
            }
            // 用户点击了确定
            if (target.dataset.modalConfirm !== undefined) {
                div.remove();
                resolve(true);
            }
        }
        document.body.append(div);
    })
}

